package com.ruoyi.web.controller.airplane;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.vo.AppActivityStatsTaskProgressVO;
import com.ruoyi.system.domain.vo.AppActivityStatsTaskFailInfoVO;
import com.ruoyi.system.domain.vo.AppActivityTrendVO;
import com.ruoyi.system.domain.vo.TbAirplaneMapVO;
import com.ruoyi.system.domain.vo.TbTaskProgressVO;
import com.ruoyi.system.service.IAppActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;


@RestController
@RequestMapping("/system/dashboard/app/activity")
@Api(tags = "应用活动数据看板")
public class AppActivityDashboardController extends BaseController {

    @Autowired
    private IAppActivityService appActivityService;

    /**
     * 获取应用活动趋势数据
     *
     * @param startDate 开始日期 (格式: yyyy-MM-dd)
     * @param endDate   结束日期 (格式: yyyy-MM-dd)
     * @return 趋势数据
     */

    @GetMapping("/trend")
    @ApiOperation("获取应用活动趋势数据")
    public R<List<AppActivityTrendVO>> getAppActivityTrend(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate
            , @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate
            , @RequestParam(required = false) String planeCode) {
        List<AppActivityTrendVO> data = appActivityService.getActivityTrendData(startDate, endDate, planeCode);
        return R.ok(data);
    }

    /**
     * 获取应用活动统计数据
     *
     * @param startDate 查询日期 (格式: yyyy-MM-dd)
     * @return 统计数据
     */
    @GetMapping("/stats/task/progress")
    @ApiOperation("获取应用任务推进度统计数据/环形图")
    public R<List<AppActivityStatsTaskProgressVO>> getAppActivityStats(
            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate
            , @RequestParam(required = false) String planeCode) {
        List<AppActivityStatsTaskProgressVO> stats = appActivityService.getActivityStatsProgress(startDate,
                endDate,planeCode);
        return R.ok(stats);
    }


    @GetMapping("/stats/task/fail/device/list")
    @ApiOperation("获取应用任务推进度统计数据/分页列表")
    public TableDataInfo getAppActivityStatsFailDeviceList(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
                                                           @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate
    ,@RequestParam(required = false) String planeCode) {
        startPage();
        List<AppActivityStatsTaskFailInfoVO> stats = appActivityService.getAppActivityStatsFailDeviceList(startDate, endDate,planeCode);
        return getDataTable(stats);
    }


    @GetMapping("/stats/task/progress/list")
    @ApiOperation("获取任务推进度统计数据/进度图")
    public R<List<TbTaskProgressVO>> getAppActivityStatsTaskProgress(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate
            , @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate
            , @RequestParam(required = false) String planeCode) {

        List<TbTaskProgressVO> stats = appActivityService.getAppActivityTaskProgress(startDate, endDate, planeCode);
        return R.ok(stats);
    }


    @GetMapping("/stats/airplane/map/list")
    @ApiOperation("地图概览")
    public R<List<TbAirplaneMapVO>> getAirPlaneMap(@RequestParam(required = false) String planeCode
            ,@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate
            , @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate) {

        List<TbAirplaneMapVO> stats = appActivityService.getAirPlaneMap(planeCode,startDate, endDate);
        return R.ok(stats);
    }

}
